package org.softmed.rest.editor.comps.full;

import java.awt.Color;

import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JLabel;

import net.miginfocom.swing.MigLayout;

import org.softmed.rest.editor.EditorUtil;
import org.softmed.rest.editor.FilePathAware;
import org.softmed.rest.editor.FilePathProvider;
import org.softmed.rest.editor.commons.SwingUtil;
import org.softmed.rest.editor.commons.URIProvider;
import org.softmed.rest.editor.comps.ApplicationEditor;
import org.softmed.rest.editor.comps.utils.DeletePanel;
import org.softmed.rest.editor.comps.utils.FieldPanel;
import org.softmed.rest.editor.comps.utils.list.ListFieldPanel;
import org.softmed.rest.editor.comps.utils.list.showListFieldDetails;

public class ApplicationEditorFull extends ApplicationEditor implements
		getDeletePanel, showListFieldDetails, FilePathAware {

	DeletePanel deletePanel = new DeletePanel(this);

	ListFieldPanel list = new ListFieldPanel("Modules", "modules",
			ModuleEditorFull.class, this);

	public ApplicationEditorFull(URIProvider uriProvider) throws Throwable {
		super(uriProvider);
		setup();
	}

	public void setup() {
		// setFullBackground(Color.WHITE);
		// setFullBackground(new Color(155, 184, 131));
		// setFullBackground(new Color(92, 137, 122));
		setFullBackground(new Color(224, 224, 255));

		// setFullBackground(Color.PINK);

		setBorder(BorderFactory.createLineBorder(Color.GRAY));
		active.setText("Active");
		// SwingUtil.setSize(this, EditorUtil.smallestWidth,
		// EditorUtil.smallestHeight);
		MigLayout layout = new MigLayout("left, insets "
				+ EditorUtil.smallestInsets + ", gap 0");
		setLayout(layout);

		// name.setBorder(EditorUtil.buttonBorder);
		// relativeURI.setBorder(EditorUtil.buttonBorder);

		JLabel title = new JLabel("Application");
		title.setFont(SwingUtil.editorTitleFont);
		add(title, "w 73!");
		add(id, "w 25!");
		add(active, "w 70! ");
		add(new JLabel("Name"), "w 33!");
		add(name, "w 120!, h " + EditorUtil.textFieldHeight + "!");
		add(Box.createHorizontalStrut(20));
		add(new JLabel("URI"), "w 25!");
		add(relativeURI, "w 152!, h " + EditorUtil.textFieldHeight + "!");
		add(deletePanel, "wrap");
		add(list, "span 10, wrap");

	}

	public void setFullBackground(Color color) {
		setBackground(color);
		list.setFullBackground(color);
		active.setBackground(color);
		deletePanel.setBackground(color);
		maxMinPanel.setBackground(color);
	}

	public void setEntity(Object entity) throws Throwable {
		super.setEntity(entity);
		// list.setEntityRefresh();
	}

	@Override
	public DeletePanel getDeletePanel() {
		return deletePanel;
	}

	@Override
	public void hideListFieldDetails() {
		list.hideListFieldDetails();

	}

	@Override
	public void showListFieldDetails() throws Throwable {
		list.showListFieldDetails();

	}

	@Override
	public void setFilePathProvider(FilePathProvider provider) {
		list.setFilePathProvider(provider);

	}

	@Override
	public void customMaximize() {
		// field.setVisible(true);
		// list.setVisible(true);
		// SwingUtil.setSize(this, 632, 120);
		// SwingUtil.setMinSize(this, 632, 100);

	}

	@Override
	public void customMinimize() {
		// field.setVisible(false);
		// list.setVisible(false);
		// SwingUtil.setSize(this, 632, 30);

	}

}
